package com.ehome.poct.terminal.controller;

import com.ehome.poct.terminal.api.constant.DeviceType;
import com.ehome.poct.terminal.api.dto.ErrorLogDTO;
import com.ehome.poct.terminal.api.dto.LogUploadCallbackDTO;
import com.ehome.poct.terminal.api.dto.SyncLogCallbackDTO;
import com.ehome.poct.terminal.api.fegin.TestDeviceLogFeginClient;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Api(tags = "日志上传")
@ApiSupport(author = "路飞")
@RestController
@RequestMapping("/test_log")
public class LogController {

    @Autowired
    TestDeviceLogFeginClient testDeviceLogFeginClient;

    @ApiOperation("错报日志上传")
    @ApiOperationSupport(author = "路飞", order = 1)
    @PostMapping("/error_log")
    public void errorLog(@RequestBody List<ErrorLogDTO> list)  {
        for (ErrorLogDTO dto : list) {
            dto.setDeviceType(DeviceType.getDeviceTypeEnum(dto.getProjectName()).getDeviceType());
            testDeviceLogFeginClient.errorLogSave(dto);
        }
    }

    @ApiOperation("日志同步回调")
    @ApiOperationSupport(author = "路飞", order = 2)
    @PostMapping("/sync_log_callback")
    public void syncLogCallback(@RequestBody SyncLogCallbackDTO dto)  {
        testDeviceLogFeginClient.syncLogCallback(dto);
    }

    @ApiOperation("日志上传回调")
    @ApiOperationSupport(author = "路飞", order = 3)
    @PostMapping("/log_upload_callback")
    public void logUploadCallback(@RequestBody LogUploadCallbackDTO dto)  {
        testDeviceLogFeginClient.logUploadCallback(dto);
    }
}
